/**
 * Copyright 2008 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kiff.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Forum Global LoaderSetting.
 * @author Adam
 * @version $Id: Setting.java 71 2008-11-26 21:03:06Z a.ruggles $
 */
@Entity @Table(name = "settings")
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Setting implements CoreEntity<String> {
	/**
	 * Serial Version UID.
	 */
	private static final long serialVersionUID = 9036381408566373593L;

	/**
	 * Site Description ID.
	 */
	public static final String SITE_DESCRIPTION = "siteDescription";

	/**
	 * The name of the Global Access Control List for all forums.
	 */
	public static final String GLOBAL_ACL_NAME = "acl";

	/**
	 * Site Name ID.
	 */
	public static final String SITE_NAME = "siteName";

	/**
	 * Version LoaderSetting ID.
	 */
	public static final String VERSION = "version";

	/**
	 * The id of the setting.
	 */
	private String id;

	/**
	 * The value of the setting.
	 */
	private String value;

	/**
	 * Default Constructor.
	 */
	public Setting() { }

	/**
	 * Constructs a setting with a id and a value.
	 * @param id The id of the setting.
	 * @param value The value to set for the setting.
	 */
	public Setting(final String id, final String value) {
		this.id = id;
		this.value = value;
	}

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof Setting)) {
			return false;
		}
		Setting rhs = (Setting) obj;
		return new EqualsBuilder()
			.append(id, rhs.getId())
			.append(value, rhs.getValue())
			.isEquals();
	}

	/**
	 * {@inheritDoc}
	 * @see kiff.entity.CoreEntity#getId()
	 */
	@Id
	public String getId() {
		return id;
	}

	/**
	 * Returns value.
	 * @return the value.
	 */
    @Column(name = "setting")
	public String getValue() {
		return value;
	}

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(13, 7)
			.append(id)
			.append(value)
			.toHashCode();
	}

	/**
	 * @see kiff.entity.CoreEntity#setId(java.io.Serializable)
	 */
	public void setId(final String id) {
		this.id = id;
	}

	/**
	 * Sets value.
	 * @param value The value to set.
	 */
	public void setValue(final String value) {
		this.value = value;
	}

	/**
	 * {@inheritDoc}
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
			.append("id", id)
			.append("value", value)
			.toString();
	}
}
